package com.example.roadeyeserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.roadeyeserver.entity.GantryRoadAreaInfo;
import com.example.roadeyeserver.entity.vo.GantryRoadAreaInfoVO;
import com.example.roadeyeserver.mapper.GantryRoadAreaInfoMapper;
import com.example.roadeyeserver.result.Result;
import com.example.roadeyeserver.service.GantryRoadAreaInfoService;
import com.example.roadeyeserver.util.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class GantryRoadAreaInfoServiceImpl extends ServiceImpl<GantryRoadAreaInfoMapper, GantryRoadAreaInfo> implements GantryRoadAreaInfoService {

    @Resource
    private GantryRoadAreaInfoMapper gantryRoadAreaInfoMapper;

    @Override
    public Result<List<GantryRoadAreaInfoVO>> getAllRoad() {
        // 查询所有信息，并根据路段编码进行分组
        List<GantryRoadAreaInfoVO> roadInfos = gantryRoadAreaInfoMapper.getAllRoad();
        return ResultUtil.success(roadInfos);
    }

    @Override
    public Result<List<GantryRoadAreaInfoVO>> getAllArea() {
        // 查询所有信息，并根据区域进行分组
        List<GantryRoadAreaInfoVO> areaInfos = gantryRoadAreaInfoMapper.getAllArea();
        return ResultUtil.success(areaInfos);
    }

//    @PostConstruct
    public void createTable() {
        log.info("开始创建gantry_road_area_info");
        gantryRoadAreaInfoMapper.createTable();
        log.info("gantry_road_area_info创建完成");
        List<GantryRoadAreaInfo> list = this.list();
        log.info("gantry_road_area_info数据量:{},数据:{}", list.size(), list);
    }
}
